/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package rpt.bd.cenario;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;

/**
 *
 * @author Roberto
 */
/**************************************************************************/
/***                                                                    ***/
/**************************************************************************/

public class COuvinteColunaGradeBd extends MouseAdapter {

    protected CGrade fGrade;
    protected CModeloGrade fModeloGrade;

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public COuvinteColunaGradeBd(CGrade aGrade) {
      fGrade = aGrade;
      fModeloGrade = (CModeloGrade)fGrade.getModel();
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    @Override
    public void mouseClicked(MouseEvent e) {
        TableColumnModel colModel = fGrade.getColumnModel();
        int columnModelIndex = colModel.getColumnIndexAtX(e.getX());
        int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex();
        boolean vOrdenacaoAscendente = fModeloGrade.getOrdenacaoAscendente();
        int vIndiceColunaOrdenada = fModeloGrade.getIndiceColunaOrdenada();

        if (modelIndex < 0)
            return;
        if (vIndiceColunaOrdenada == modelIndex)
            fModeloGrade.setOrdenacaoAscendente(!vOrdenacaoAscendente);
        else
            fModeloGrade.setIndiceColunaOrdenada(modelIndex);

        for (int vContador = 0; vContador < fModeloGrade.getColumnCount(); vContador++) {
            TableColumn column = colModel.getColumn(vContador);
            column.setHeaderValue(fModeloGrade.getColumnName(column.getModelIndex()));
        }
        fGrade.getTableHeader().repaint();
        fGrade.ordenar(fModeloGrade);

        //Collections.sort(vector,new MyComparator(isSortAsc));
        //table.tableChanged(new TableModelEvent(MyTableModel.this));
        fGrade.repaint();

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    }
}
